﻿using System;
using System.Drawing;
using System.Windows.Forms;
using SalaryReport.Core.Events;

namespace SalaryReport.Core.Excel
{
    [Serializable]
    public class ExcelCell : ExcelItem
    {
        private readonly TextBox txtRowNumber;
        private readonly ComboBox cbColumn;

        public int Row
        {
            get
            {
                var num = 0;
                if (!int.TryParse(txtRowNumber.Text, out num))
                {
                    Notify(new SalaryArgs(string.Format("Parsing error for setting with name: {0}", Name)));
                }
                return num;
            }
            set { txtRowNumber.Text = value.ToString(); }
        }

        public ExcelColumnName Column
        {
            get { return (ExcelColumnName)cbColumn.SelectedItem; }
            set { cbColumn.SelectedItem = value; }
        }

        public ExcelCell()
        {
            cbColumn = new ComboBox
                           {
                               Width = boxNumSize,
                               Location = new Point(btnSize + boxSize * 2 + margin * 4, margin)
                           };
            var names = Enum.GetValues(typeof(ExcelColumnName));
            foreach (var name in names)
            {
                cbColumn.Items.Add(name);
            }
            cbColumn.SelectedItem = ExcelColumnName.A;
            txtRowNumber = new TextBox
                               {
                                   Width = boxNumSize,
                                   Location = new Point(btnSize + boxSize * 2 + margin * 5 + boxNumSize, margin)
                               };
            container.Controls.Add(txtRowNumber);
            container.Controls.Add(cbColumn);
        }
    }
}